package com.yijiu.trb;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.yijiu.action.BaseAction;
import com.yijiu.network.Request;
import com.yijiu.network.StringUtils;
import com.yijiu.resource.ActionType;
import com.yijiu.resource.C;
import com.yijiu.resource.CacheData;
import com.yijiu.response.BaseResponse;
import com.yijiu.response.UploadFileResponse;
import com.yijiu.utils.ConvertUtils;
import com.yijiu.utils.IDCheck;
import com.yijiu.utils.ImageUtils;
import com.zvezda.algorithm.utils.AlgorithmUtils;

/**
 * 实名认证
 * 
 * @author TangChao
 */
public class RealInfoActivity extends BTitleActivity implements android.view.View.OnClickListener
{
	
	private String tag = "";
	
	/**
	 * 真实姓名编辑框
	 */
	private EditText nameEditText;
	
	/**
	 * 证件号码编辑框
	 */
	private EditText cardNumEditText;
	
	/**
	 * 身份证到期时间设置文字提示
	 */
	TextView cardTimeOutTextView;
	
	/**
	 * 上传正面提示
	 */
	TextView cardFrontTextView;
	
	/**
	 * 上传反面提示
	 */
	TextView cardBackTextView;
	
	/**
	 * 身份证正面
	 */
	private ImageView cardFrontImageView;
	
	/**
	 * 展示用身份证正面图片
	 */
	private ImageView cardFrontImageViewShow;
	
	/**
	 * 身份证反面
	 */
	private ImageView cardBackImageView;
	
	/**
	 * 展示用身份证反面图片
	 */
	private ImageView cardBackImageViewShow;
	
	/**
	 * 返回的正面路径
	 */
	private String filePathFrontSevice;
	
	/**
	 * 返回的反面路径
	 */
	private String filePathBackSevice;
	
	/**
	 * 长期按钮
	 */
	private CheckBox cardTimeOutCheckBox;
	
	/**
	 * 身份证到期时间
	 */
	private String timeOutStr;
	
	/**
	 * 身份证到期时间
	 */
	private String longTimeStr;
	
	/**
	 * 日期选择控件按钮
	 */
	private ImageView ivSetDate;
	
	/**
	 * 真实姓名
	 */
	private String realNameStr;
	
	/**
	 * 身份证号码
	 */
	private String cardNumStr;
	
	/**
	 * 提交按钮
	 */
	private TextView submit;
	
	private static final String IMAGE_FILE_LOCATION = "file:///sdcard/temp.jpg";
	
	private Uri imageUri;// to store the big bitmap
	
	private static final int TAKE_SMALL_PICTURE = 2;
	
	private static final int CROP_SMALL_PICTURE = 4;
	
	private static final int CHOOSE_SMALL_PICTURE = 6;
	
	private String flag = "front";
	
	/**
	 * 拍摄的图片
	 */
	private Bitmap takeBitmap;
	
	/**
	 * 选取的图片
	 */
	private Bitmap bitmapChoose;
	
	/**
	 * 长期按钮点击监听器
	 */
	private OnCheckedChangeListener cardTimeOutLongTimeOrNot = new OnCheckedChangeListener()
	{
		
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
		{
			if (isChecked)
			{
				longTimeStr = "longTime";
				timeOutStr = "长期";
				ivSetDate.setEnabled(false);
			}
			else
			{
				ivSetDate.setEnabled(true);
				if ("".equals(timeOutStr) || "长期".equals(timeOutStr))
				{
					timeOutStr = "点击右图设置";
					longTimeStr = "";
				}
				else
				{
					longTimeStr = timeOutStr;
				}
			}
			cardTimeOutTextView.setText(timeOutStr);
		}
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		setContentView(R.layout.activity_real_info);
		initWidget();
	}
	
	/**
	 * 初始化控件
	 */
	@Override
	protected void initWidget()
	{
		titleView.setText("实名资料");
		imageUri = Uri.parse(IMAGE_FILE_LOCATION);
		nameEditText = (EditText) findViewById(R.id.et_real_info_name);
		cardNumEditText = (EditText) findViewById(R.id.et_real_info_card_num);
		cardTimeOutTextView = (TextView) findViewById(R.id.tv_real_info_card_timeout);
		ivSetDate = (ImageView) findViewById(R.id.iv_real_info_date);
		/*------------------------------------------*/
		cardFrontTextView = (TextView) findViewById(R.id.tv_real_info_front);
		cardBackTextView = (TextView) findViewById(R.id.tv_real_info_back);
		cardFrontTextView.setBackgroundResource(R.drawable.real_info_pic);
		cardBackTextView.setBackgroundResource(R.drawable.real_info_pic);
		cardFrontImageView = (ImageView) findViewById(R.id.iv_real_info_front);
		cardBackImageView = (ImageView) findViewById(R.id.iv_real_info_back);
		cardFrontImageViewShow = (ImageView) findViewById(R.id.iv_real_info_front_show);
		cardBackImageViewShow = (ImageView) findViewById(R.id.iv_real_info_back_show);
		cardFrontImageView.setVisibility(View.GONE);
		cardBackImageView.setVisibility(View.GONE);
		/*--------------------------------------------*/
		cardTimeOutCheckBox = (CheckBox) findViewById(R.id.cb_real_info_long_time);
		cardTimeOutCheckBox.setOnCheckedChangeListener(cardTimeOutLongTimeOrNot);
		submit = (TextView) findViewById(R.id.btn_real_info_submit);
		submit.setOnClickListener(this);
		nameEditText.setText(CacheData.REAL_NAME);
		String cardNum = CacheData.CERT_NUM;
		if (cardNum.equals("null") || cardNum.equals(""))
		{
			cardNumEditText.setHint("请输入证件号码");
		}
		else
		{
			cardNumEditText.setText(CacheData.CERT_NUM);
		}
		if (tag != null && tag.equals("ACTIVE_DONE_ACTIVITY"))
		{
			return;
		}
		/**
		 * 判断是否实名认证
		 */
		if (CacheData.REAL_NAME_STATUS.equals("IS") || CacheData.REAL_NAME_STATUS.equals("IN"))
		{
			nameEditText.setFocusable(false);
			cardNumEditText.setFocusable(false);
			if (CacheData.CARD_OFF.equals("longTime"))
			{
				cardTimeOutTextView.setText("长期");
			}
			cardTimeOutTextView.setText("longtime".equals(CacheData.CARD_OFF) ? "长期" : "长期");
			ivSetDate.setVisibility(View.GONE);
			cardTimeOutCheckBox.setVisibility(View.GONE);
			submit.setEnabled(false);
			submit.setText("状态：" + ConvertUtils.checkRealNameStatus(CacheData.REAL_NAME_STATUS));
			submit.setBackgroundResource(R.drawable.btn_login_bg_false);
			/*---------------------------------------*/
			cardFrontTextView.setVisibility(View.GONE);
			cardBackTextView.setVisibility(View.GONE);
			ImageUtils.setImage(CacheData.CERT_FRONT_PATH, cardFrontImageView);
			ImageUtils.setImage(CacheData.CERT_BACK_PATH, cardBackImageView);
			cardFrontImageView.setVisibility(View.VISIBLE);
			cardBackImageView.setVisibility(View.VISIBLE);
			cardFrontImageViewShow.setVisibility(View.GONE);
			cardBackImageViewShow.setVisibility(View.GONE);
			findViewById(R.id.flayout_real_info_front).setEnabled(false);
			findViewById(R.id.blayout_real_info_back).setEnabled(false);
		}
	}
	
	public void showRestPhotoDialog(final Activity context, int arrayId)
	{
		final Dialog dialog = new Dialog(context, R.style.dialogTaxis);
		View view = LayoutInflater.from(context).inflate(R.layout.taxis_layout, null);
		((TextView) view.findViewById(R.id.taxis_text_title)).setText("选择图片来源");
		ListView list = (ListView) view.findViewById(R.id.taxis_item_list);
		List<HashMap<String, Object>> taxisList = new ArrayList<HashMap<String, Object>>();
		String[] taxisStr = context.getResources().getStringArray(arrayId);
		for (int i = 0; i < taxisStr.length; i++)
		{
			HashMap<String, Object> data = new HashMap<String, Object>();
			data.put("username", taxisStr[i]);
			taxisList.add(data);
		}
		list.setAdapter(new SimpleAdapter(context, taxisList, R.layout.taxis_item_layout, new String[]
		{
			"username"
		}, new int[]
		{
			R.id.taxis_name
		}));
		list.setOnItemClickListener(new OnItemClickListener()
		{
			
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
			{
				dialog.dismiss();
				switch (arg2)
				{
					case 0:
					{
						String status = Environment.getExternalStorageState();
						if (status.equals(Environment.MEDIA_MOUNTED))
						{
							// 判断是否有SD卡
							Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// action
																						// is
																						// capture
							intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
							startActivityForResult(intent, TAKE_SMALL_PICTURE);
						}
						else
						{
							// showToast("没有SD卡");
						}
						break;
					}
					case 1:
						String status = Environment.getExternalStorageState();
						if (status.equals(Environment.MEDIA_MOUNTED))
						{
							Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
							intent.setType("image/*");
							intent.putExtra("crop", "true");
							intent.putExtra("aspectX", 3);
							intent.putExtra("aspectY", 2);
							intent.putExtra("outputX", 300);
							intent.putExtra("outputY", 200);
							intent.putExtra("scale", true);
							intent.putExtra("return-data", true);
							intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
							intent.putExtra("noFaceDetection", true); // no face
																		// detection
							startActivityForResult(intent, CHOOSE_SMALL_PICTURE);
						}
						else
						{
						}
						break;
				}
			}
		});
		dialog.setContentView(view);
		dialog.show();
		dialog.setCanceledOnTouchOutside(true);
	}
	
	/**
	 * 按钮点击
	 * 
	 * @param v
	 */
	public void realInfoClick(View v)
	{
		switch (v.getId())
		{
			case R.id.iv_real_info_date:// 选择日期
			{
				settingDateDialog();
			}
				break;
			case R.id.flayout_real_info_front:// 上传正面
			{
				if (!CacheData.REAL_NAME_STATUS.equals("IS"))
				{
					flag = "front";
					showRestPhotoDialog(this, R.array.taxis_item);
				}
				else
				{
					app.showMsg("实名认证后不可修改身份证图片");
				}
			}
				break;
			case R.id.blayout_real_info_back:// 上传反面
			{
				if (!CacheData.REAL_NAME_STATUS.equals("IS"))
				{
					flag = "back";
					showRestPhotoDialog(this, R.array.taxis_item);
				}
				else
				{
					app.showMsg("实名认证后不可修改身份证图片");
				}
			}
				break;
			default:
				break;
		}
	}
	
	/**
	 * 检查输入信息
	 */
	private boolean checkInput()
	{
		realNameStr = nameEditText.getText().toString();
		cardNumStr = cardNumEditText.getText().toString();
		CacheData.CERT_NUM = cardNumStr;
		if (StringUtils.isNull(realNameStr))
		{
			app.showMsg("请输入真实姓名");
			return false;
		}
		if (StringUtils.isNull(cardNumStr))
		{
			app.showMsg("请输入证件号码");
			return false;
		}
		if (!IDCheck.checkID(cardNumStr))
		{
			app.showMsg("请输入有效的证件号码");
			return false;
		}
		if (!cardTimeOutCheckBox.isChecked() && (longTimeStr == null || longTimeStr.length() == 0))
		{
			app.showMsg("请设置身份证到期时间");
			return false;
		}
		return true;
	}
	
	/**
	 * 上传文件
	 */
	private void appFileUpload(final Bitmap bit, final String fileExt, final int type)
	{
		if (!checkInput())
		{
			changeSubmitButtonOn();
			return;
		}
		showProgress("正在提交身份证图片，请稍候！");
		new Thread(new Runnable()
		{
			
			@Override
			public void run()
			{
				String inputStr = null;
				try
				{
					inputStr = "service=appFileUploadService&file="
							+ AlgorithmUtils.byte2hex(readStream(Bitmap2InputStream(bit))) + "&fileExt=" + fileExt;
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
				// AES加密
				encryptBase(inputStr, C.PRIVATE_KEY);
				// 封装上传的数据
				BaseAction baseAction = new BaseAction(encodedData, encriptData);
				UploadFileResponse uploadFileResponse = new UploadFileResponse();
				Request r = new Request(baseAction, uploadFileResponse, type);
				netManager.excute(r, RealInfoActivity.this, RealInfoActivity.this);
			}
		}).start();
	}
	
	/**
	 * 更新实名认证信息
	 */
	private void updateRealNameInfo()
	{
		// 将用户输入的信息拼接成字符串上传给服务器
		String inputStr = "service=updateRealNameInfoService&realName=" + realNameStr + "&certNo=" + cardNumStr
				+ "&cardOff=" + longTimeStr + "&certFrontPath=" + filePathFrontSevice + "&certBackPath="
				+ filePathBackSevice;
		// AES加密
		encryptBase(inputStr, C.PRIVATE_KEY);
		// 封装上传的数据
		BaseAction baseAction = new BaseAction(encodedData, encriptData, CacheData.APP_KEY);
		BaseResponse baseResponse = new BaseResponse();
		Request r = new Request(baseAction, baseResponse, ActionType.UPDATE_REAL_INFO);
		netManager.excute(r, this, this);
		showProgress("正在提交实名资料，请稍候！");
	}
	
	/**
	 * 发送实名认证
	 * 
	 * @param filePath
	 * @param pointStr
	 * @param type
	 */
	private void sendRealName()
	{
		String inputStr = "service=sendRealNameService";
		// AES加密
		encryptBase(inputStr, C.PRIVATE_KEY);
		// 封装上传的数据
		BaseAction baseAction = new BaseAction(encodedData, encriptData, CacheData.APP_KEY);
		BaseResponse baseResponse = new BaseResponse();
		Request r = new Request(baseAction, baseResponse, ActionType.SEND_REAL_INFO);
		netManager.excute(r, this, this);
		showProgress("正在发送实名认证，请稍候！");
	}
	
	/* 操作成功返回的函数 */
	@Override
	public void getResult(Request r)
	{
		super.getResult(r);
		switch (r.getType())
		{
			case ActionType.UPLOAD_PIC_ONE:
				UploadFileResponse uploadFileResponseFront = (UploadFileResponse) r.getResponse();
				filePathFrontSevice = uploadFileResponseFront.uploadFile.filePath;
				app.showMsg("提交身份证正面图片成功！");
				if (takeBitmap != null)
				{
					if ("front".equals(flag))
					{
						cardFrontImageViewShow.setImageBitmap(takeBitmap);
						cardFrontTextView.setVisibility(View.GONE);
					}
					else if ("back".equals(flag))
					{
						cardBackImageViewShow.setImageBitmap(takeBitmap);
						cardBackTextView.setVisibility(View.GONE);
					}
				}
				if (bitmapChoose != null)
				{
					if ("front".equals(flag))
					{
						cardFrontImageViewShow.setImageBitmap(bitmapChoose);
						cardFrontTextView.setVisibility(View.GONE);
					}
					else if ("back".equals(flag))
					{
						cardBackImageViewShow.setImageBitmap(bitmapChoose);
						cardBackTextView.setVisibility(View.GONE);
					}
				}
				break;
			case ActionType.UPLOAD_PIC_TWO:
				UploadFileResponse uploadFileResponseBack = (UploadFileResponse) r.getResponse();
				filePathBackSevice = uploadFileResponseBack.uploadFile.filePath;
				app.showMsg("提交身份证反面图片成功！");
				if (takeBitmap != null)
				{
					if ("front".equals(flag))
					{
						cardFrontImageViewShow.setImageBitmap(takeBitmap);
						cardFrontTextView.setVisibility(View.GONE);
					}
					else if ("back".equals(flag))
					{
						cardBackImageViewShow.setImageBitmap(takeBitmap);
						cardBackTextView.setVisibility(View.GONE);
					}
				}
				if (bitmapChoose != null)
				{
					if ("front".equals(flag))
					{
						cardFrontImageViewShow.setImageBitmap(bitmapChoose);
						cardFrontTextView.setVisibility(View.GONE);
					}
					else if ("back".equals(flag))
					{
						cardBackImageViewShow.setImageBitmap(bitmapChoose);
						cardBackTextView.setVisibility(View.GONE);
					}
				}
				break;
			case ActionType.UPDATE_REAL_INFO:
				sendRealName();
				break;
			case ActionType.SEND_REAL_INFO:
				if (!CacheData.LOGIN_STATUS)
				{
					AlertDialog dialogUnLogin = new AlertDialog.Builder(this).setTitle("实名认证信息发送成功")
							.setPositiveButton("登录", new DialogInterface.OnClickListener()
							{
								
								@Override
								public void onClick(DialogInterface dialog, int which)
								{
									initIntent(RealInfoActivity.this, LoginActivity.class);
									finish();
								}
							}).setNegativeButton("绑定银行卡", new OnClickListener()
							{
								
								@Override
								public void onClick(DialogInterface dialog, int which)
								{
									initIntent(RealInfoActivity.this, MyBankCardActivity.class);
									finish();
								}
							}).create();
					dialogUnLogin.show();
				}
				else
				{
					AlertDialog dialogLogin = new AlertDialog.Builder(this).setTitle("实名认证信息发送成功")
							.setNeutralButton("确定", new DialogInterface.OnClickListener()
							{
								
								@Override
								public void onClick(DialogInterface dialog, int which)
								{
									finish();
								}
							}).setNegativeButton("绑定银行卡", new OnClickListener()
							{
								
								@Override
								public void onClick(DialogInterface dialog, int which)
								{
									initIntent(RealInfoActivity.this, MyBankCardActivity.class);
									finish();
								}
							}).create();
					dialogLogin.show();
				}
				changeSubmitButtonOn();
				break;
		}
	}
	
	/* 操作失败返回的函数 */
	@Override
	public void notifyError(int type, int errorCode, String errorMsg)
	{
		super.notifyError(type, errorCode, errorMsg);
		changeSubmitButtonOn();
		switch (type)
		{
			case ActionType.UPLOAD_PIC_ONE:
				app.showMsg(errorMsg);
				break;
			case ActionType.UPLOAD_PIC_TWO:
				app.showMsg(errorMsg);
				break;
			case ActionType.UPDATE_REAL_INFO:
				app.showMsg(errorMsg);
				break;
			case ActionType.SEND_REAL_INFO:
				String str = "申请正在处理中,不能重复提交";
				if (str.equals(errorMsg))
				{
					if (!CacheData.LOGIN_STATUS)
					{
						AlertDialog dialogUnLogin = new AlertDialog.Builder(this).setTitle("实名认证信息发送成功")
								.setPositiveButton("登录", new DialogInterface.OnClickListener()
								{
									
									@Override
									public void onClick(DialogInterface dialog, int which)
									{
										initIntent(RealInfoActivity.this, LoginActivity.class);
										finish();
									}
								}).setNegativeButton("绑定银行卡", new OnClickListener()
								{
									
									@Override
									public void onClick(DialogInterface dialog, int which)
									{
										initIntent(RealInfoActivity.this, MyBankCardActivity.class);
										finish();
									}
								}).create();
						dialogUnLogin.show();
					}
					else
					{
						
						AlertDialog dialogLogin = new AlertDialog.Builder(this).setTitle("实名认证信息发送成功")
								.setPositiveButton("确定", new DialogInterface.OnClickListener()
								{
									
									@Override
									public void onClick(DialogInterface dialog, int which)
									{
										finish();
									}
								}).setNegativeButton("绑定银行卡", new OnClickListener()
								{
									
									@Override
									public void onClick(DialogInterface dialog, int which)
									{
										initIntent(RealInfoActivity.this, MyBankCardActivity.class);
										finish();
									}
								}).create();
						dialogLogin.show();
					}
					changeSubmitButtonOn();
				}
				else
				{
					app.showMsg(errorMsg);
				}
				break;
		}
	}
	
	/* 重复提交返回的函数 */
	@Override
	public void rePost(Request r)
	{
		super.rePost(r);
	}
	
	/**
	 * 选择日期的控件
	 */
	private void settingDateDialog()
	{
		Time time = new Time("GTM-8");
		time.setToNow();
		DatePickerDialog datePickerDialog = new DatePickerDialog(this, new OnDateSetListener()
		{
			
			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
			{
				Date date = new Date((year - 1900), monthOfYear, dayOfMonth);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				timeOutStr = sdf.format(date);
				longTimeStr = timeOutStr;
				cardTimeOutTextView.setText(timeOutStr);
			}
		}, time.year, time.month, time.monthDay);
		datePickerDialog.show();
	}
	
	public static byte[] readStream(InputStream inStream) throws Exception
	{
		byte[] buffer = new byte[1024];
		int len = -1;
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		while ((len = inStream.read(buffer)) != -1)
		{
			outStream.write(buffer, 0, len);
		}
		byte[] data = outStream.toByteArray();
		outStream.close();
		inStream.close();
		return data;
	}
	
	/**
	 * 图片转为字节数组流
	 * 
	 * @param bm
	 * @return
	 */
	public InputStream Bitmap2InputStream(Bitmap bm)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
		InputStream is = new ByteArrayInputStream(baos.toByteArray());
		return is;
	}
	
	private void cropImageUri(Uri uri, int requestCode)
	{
		Intent intent = new Intent("com.android.camera.action.CROP");
		intent.setDataAndType(uri, "image/*");
		intent.putExtra("crop", "true");
		intent.putExtra("aspectX", 3);
		intent.putExtra("aspectY", 2);
		intent.putExtra("outputX", 300);
		intent.putExtra("outputY", 200);
		intent.putExtra("scale", true);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
		intent.putExtra("return-data", false);
		intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
		intent.putExtra("noFaceDetection", true); // no face detection
		startActivityForResult(intent, requestCode);
	}
	
	private Bitmap decodeUriAsBitmap(Uri uri)
	{
		Bitmap bitmap = null;
		try
		{
			bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
			return null;
		}
		return bitmap;
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode != Activity.RESULT_OK)
		{
			Toast.makeText(this, "获取图片失败,请重试", Toast.LENGTH_SHORT).show();
			return;
		}
		else
		{
			switch (requestCode)
			{
				case TAKE_SMALL_PICTURE:// 裁剪照片
					cropImageUri(imageUri, CROP_SMALL_PICTURE);
					break;
				case CROP_SMALL_PICTURE:
					if (imageUri != null)
					{
						takeBitmap = decodeUriAsBitmap(imageUri);
						if ("front".equals(flag))
						{
							appFileUpload(takeBitmap, ".jpg", ActionType.UPLOAD_PIC_ONE);
						}
						else if ("back".equals(flag))
						{
							appFileUpload(takeBitmap, ".jpg", ActionType.UPLOAD_PIC_TWO);
						}
					}
					else
					{
						Log.e(TAG, "CROP_SMALL_PICTURE: data = " + data);
					}
					break;
				case CHOOSE_SMALL_PICTURE:// 选择照片
					if (data != null)
					{
						bitmapChoose = data.getParcelableExtra("data");
						if ("front".equals(flag))
						{
							appFileUpload(bitmapChoose, ".jpg", ActionType.UPLOAD_PIC_ONE);
						}
						else if ("back".equals(flag))
						{
							appFileUpload(bitmapChoose, ".jpg", ActionType.UPLOAD_PIC_TWO);
						}
					}
					else
					{
						Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data);
					}
					break;
				default:
					break;
			}
		}
	}
	
	private void changeSubmitButtonOn()
	{
		submit.setEnabled(true);
		submit.setBackgroundResource(R.drawable.login_background);
		submit.setText("提交");
	}
	
	private void changeSubmitButtonOff()
	{
		submit.setEnabled(false);
		submit.setBackgroundResource(R.drawable.btn_login_bg_false);
		submit.setText("正在提交");
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.btn_real_info_submit:// 提交按钮
				changeSubmitButtonOff();
				if (StringUtils.isNull(filePathFrontSevice) || StringUtils.isNull(filePathBackSevice))
				{
					app.showMsg("请先上传身份证图片！");
					changeSubmitButtonOn();
					return;
				}
				updateRealNameInfo();
				break;
			default:
				break;
		}
	}
}
